/*
 *    ItemSet.java
 *    Copyright (C) 2011 University of Waikato, Hamilton, New Zealand
 *    @author Maciek Jarka (www.admire-project.eu)
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package moa.associations;

import java.util.ArrayList;
import java.util.List;

import weka.associations.Item;

public class ItemSet {

    private int support;

    List<Item> items;

    boolean closed, key;

    List<ItemSet> generators;

    public List<ItemSet> getGenerators() {
        return generators;
    }

    public void addGenerator(ItemSet generator) {
        this.generators.add(generator);
    }

    public boolean isGenerator(ItemSet set) {
        List<Item> items = new ArrayList<Item>(set.getItems());
        items.retainAll(this.items);
        return items.size() == this.items.size();
    }

    public void setGenerators(List<ItemSet> generators) {
        this.generators = generators;
    }

    public void setSupport(int support) {
        this.support = support;
    }

    public int getSupport() {
        return this.support;
    }

    public List<Item> getItems() {
        return items;
    }

    public void setItems(List<Item> items) {
        this.items = items;
    }

    public ItemSet(int support, List<Item> items) {
        super();
        this.generators = new ArrayList<ItemSet>();
        this.support = support;
        this.items = items;
        this.key = true;
        this.closed = true;
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof ItemSet) {
            return this.items.equals(((ItemSet) o).items) && this.support == ((ItemSet) o).support;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return this.items.size();
    }

    public String toString() {
        String s = "";
        for (Item i : this.items) {
            s += i.toString() + " ";
        }
        return s;
    }
}
